<template>
  <div class="item-one" ref="itemOne">
    <div class="title">
      <span>全部日志</span>
      <div>
        <!-- <el-button type="primary" @click="eqma = true">导出</el-button> -->
        <el-button icon="el-icon-refresh"></el-button>
      </div>
    </div>
    <div class="container">
      <div class="screeningBox">
        <div class="leftBox">
          <div class="leftitem">
            <div class="block">
              <el-date-picker
                v-model="conditions.startTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="提交起始时间"
              ></el-date-picker>
              <el-date-picker
                v-model="conditions.endTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="提交结束时间"
              ></el-date-picker>
            </div>
          </div>
          <div class="leftitem">
            <el-input class="merchants" v-model="conditions.ip" placeholder="请求ip"></el-input>
          </div>
          <div class="leftitem">
            <el-input class="merchants" v-model="conditions.requestPath" placeholder="请求路径"></el-input>
          </div>
        </div>
        <div class="rightBox">
          <div class="rightitem">
            <el-input class="merchants" v-model="conditions.servNo" placeholder="服务器编号"></el-input>
          </div>
          <div class="rightitem">
            <el-input class="merchants" v-model="conditions.username" placeholder="用户名"></el-input>
          </div>
          <div class="rightitem">
            <el-button icon="el-icon-search" type="primary" @click="soso">搜索</el-button>
            <el-button icon="el-icon-refresh" type="primary" @click="reset">重置</el-button>
          </div>
        </div>
      </div>
     
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="merchantarr"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
          :header-cell-style="tableHeaderColor"
          v-loading="loading"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column align="center" type="index" label="序号"></el-table-column>
          <el-table-column prop="username" align="center" width="65" label="用户名"></el-table-column>
          <el-table-column prop="requestPath" align="center" label="请求路径"></el-table-column>
          <el-table-column prop="ip" align="center" label="IP"></el-table-column>
          <el-table-column prop="classMethod" align="center" label="类/方法"></el-table-column>
          <el-table-column prop="servNo" align="center" width="65" label="服务器编号"></el-table-column>
          <el-table-column prop="createTime" align="center" label="时间"></el-table-column>
          <el-table-column fixed="right" align="center" label="操作" width="120">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="details(scope.row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="combined"
          ></el-pagination>
        </div>
      </div>
      <br>
      <br>
      <el-dialog v-dialogDrag title="日志详情" :visible.sync="visible" width="45%" :close-on-click-modal = "false">
        <div class="xian"><span class="big">请求路径：</span>{{loginfo.requestPath}}</div>
        <div class="xian flex">
          <div><span class="big">请求方式：</span>{{loginfo.httpMethod}}</div>
          <div><span class="big">IP地址：</span>{{loginfo.ip}}</div>
          <div><span class="big">请求处理耗时：</span>{{loginfo.consumeTime}}</div>
        </div>
        <div class="xian flex">
          <div><span class="big">类名、方法名：</span>{{loginfo.classMethod}}</div>
          <div><span class="big">用户名称：</span>{{loginfo.username}}</div>
          <div><span class="big">服务器编号：</span>{{loginfo.servNo}}</div>
        </div>
        <div class="xian"><span class="big">请求参数：</span>{{loginfo.reqStr}}</div>
        <div  class="xian"><span class="big">响应参数：</span>{{loginfo.resStr}}</div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { getservice, usersLogpage } from "@/api/api";
export default {
  name: "item-one",
  data: function() {
    return {
      tableData: [],
      cur_page: 1,
      cur_size: 10,
      multipleSelection: [],
      visible: false,
      servicearr: [],
      merchantarr: [],
      combined: 10,
      pageCount: "",
      conditions: {
        servicelevel: "",
        servicename: "",
        merchantsstate: "",
        merchantsno: "",
        stardate: "",
        enddate: "",
        serviceid: "",
        aisle: "",
        shopno: ""
      },
      loginfo:{},
      loading: true,
    };
  },
  created() {
    this.$store.dispatch("getNewNum", 6);
    // console.log(this.$store.state.changableNum);
    // console.log(this.$store.state.showFooter);
    // console.log(this.$store.state.logininfo);

    this.merchantlist();
  },
  methods: {
     //修改thead 背景色
     tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return 'background-color: #F0F0F0;font-weight: 500;'
      }
    },
    // 刷新
    refresh() {
      this.$router.go({
        path: 0,
        query: {
          t: Date.now()
        }
      })
    },
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      this.merchantlist();
      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    // 分页数量
    sizechange(val) {
      this.cur_size = val;
      this.merchantlist();

      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    //多选框
    handleSelectionChange(val) {
      console.log(val);
      this.multipleSelection = val;
    },
    //  重置
    reset() {
      this.conditions = {
        servNo:'',
        ip:'',
        username:'',
        requestPath:'',
        startTime:'',
        endTime:'',

      }
    },
    // 搜索
    soso() {
      this.cur_page = 1
      this.merchantlist()
    },

    // 商户列表
    merchantlist() {
      // console.log(this.conditions)
      this.loading = true
      usersLogpage({
        page: this.cur_page,
        size: this.cur_size,
        ...this.conditions
      }).then(res => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage. removeItem("token");
          this.$router.push("/login");
        } else {
          this.merchantarr = res.data.rows;
          this.combined = res.data.total;
          this.pageCount = res.data.totalPage;
          this.loading = false;
        }
      });
    },
    // 详情
    details(val){
      this.visible = true
      this.loginfo = val
    }
  }
};
</script>
<style scoped lang='less'>
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.name {
  width: 25%;
}
.screeningBox {
  width: 100%;
  display: flex;
}
.leftBox,
.rightBox {
  width: 50%;
  padding: 0 15px;
  box-sizing: border-box;
}
.leftBox > .leftitem {
  margin-bottom: 15px;
}
.rightBox > .rightitem {
  margin-bottom: 15px;
}
.merchants {
  width: 50%;
}
.tableBox {
  margin-top: 20px;
}
.servicename {
  width: 60%;
}

.width20 {
  width: 20%;
}
.red {
  color: #f9607d;
}
.blue {
  color: #01aaef;
}
.stitle {
  padding: 5px 0;
  font-size: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  i {
    margin-left: 10px;
    margin-right: 5px;
  }
  .swarning {
    color: red;
  }
  .warning {
    color: #f9607d;
  }
}
.big{
  font-size: 18px;
  font-weight: 600;
}
.xian{
  width: 100%;
  margin: 15px 0;
  border-bottom: 1px solid #000;
}
.flex{
  display: flex;
  div{
    flex: 1;
  }
}

</style>